﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UserService.IRepository;
using UserService.Entity;
using ORAProvider;
using UserService.Repository.Repositories;

namespace UserService.Repository
{
    public class ClientStore : IClientStore<Client>
    {
        private readonly ClientRepository _clientRepository;
        public OracleDataContext Database { get; private set; }

        public ClientStore()
            : this(new OracleDataContext())
        {
        }

        public ClientStore(OracleDataContext database)
        {
            // TODO: Compare with EntityFramework provider.
            Database = database;
            _clientRepository = new ClientRepository(database);
        }
        public bool CreateRow(Client row)
        {
            if (row == null)
            {
                throw new ArgumentException("CreateRow params row is null");
            }

            int result = _clientRepository.AddClient(row);
            if (result > 0)
                return true;

            return false;
        }

        public bool DeleteRow(Client row)
        {
            throw new NotImplementedException();
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (Database != null)
                {
                    Database.Dispose();
                    Database = null;
                }
            }
        }

        public Client FindByIdRow(string clientId)
        {
            if (clientId.Equals(""))
            {
                throw new ArgumentException("clientId");
            }

            var result = _clientRepository.GetClientById(clientId);

            return result;
        }

        public Client FindBySql(string sSql)
        {
            throw new NotImplementedException();
        }

        public bool UpdateRow(Client row)
        {
            throw new NotImplementedException();
        }
    }
}
